package com.stone.bypass.proxy.core.support;


import java.util.Map;

public interface DiversionSelector {

    String VERSION_EMPTY = "";

    String VERSION_V1 = "v1";

    Object nonDivert(Map<String, Object> proxyMap);

    Object divert(String key, Map<String, Object> proxyMap);


    class NONE implements DiversionSelector {

        @Override
        public Object nonDivert(Map<String, Object> proxyMap) {
            Object selectObj = proxyMap.get(DiversionSelector.VERSION_EMPTY);
            if (selectObj != null) {
                return selectObj;
            }
            selectObj = proxyMap.get(VERSION_V1);
            if (selectObj != null) {
                return selectObj;
            }
            throw new RuntimeException("找不到符合条件的分流对象");
        }

        @Override
        public Object divert(String key, Map<String, Object> proxyMap) {
            if (proxyMap.get(null) != null) {
                return proxyMap.get(null);
            }
            return proxyMap.get(VERSION_V1);
        }
    }
}
